@extends('layout.master')

@section('title','系统设置')

@section('css')
    @parent
    <link href="{{ asset('plugins/bower_components/summernote/dist/summernote.css') }}" rel="stylesheet"/>
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">

@endsection
@section('main')
    @if (session('message'))
        <div>
            <input type="hidden" id="hidden" name="hidden" value="hidden">
            <input type="hidden" id="message" name="message" value="{{ session('message') }}">
        </div>
    @endif
    <div class="content-wrap">
        <form class="" method="post" enctype="multipart/form-data">
            <div class="form-body">
                <div class="row">
                    <div class="col-md-12">
                        <div class="white-box">
                            <div class="row">
                                <div class="col-lg-6">
                                    <div class="form-group">
                                        <label> APP名称</label>
                                        <input type="text" class="form-control" name="app_name"
                                               value="{{ $system->app_name }}">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-12" id="sumAfter">
                                    <h3 class="box-title">APP 描述</h3>
                                    <textarea class="summernote" name="describe">{!! $system->describe !!}</textarea>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>

            </div>
            <div class="form-actions">
                <div class="row">
                    <div class="col-md-12">
                        <div class="row">
                            <div class="col-md-offset-3 col-md-9">
                                <button type="submit" class="btn btn-success"><i
                                            class="fa fa-check"></i> 保存
                                    {!! csrf_field() !!}
                                </button>
                                <button type="button" class="btn btn-reset"><i
                                            class="fa fa-circle-o-notch"></i> 重置
                                </button>
                                @if($system->status === 1)
                                    <button type="button" class="btn btn-danger app-btn-close"><i
                                                class="fa fa-circle-o-notch"></i> 关闭APP
                                    </button>
                                @else
                                    <button type="button" class="btn btn-danger app-btn-open"><i
                                                class="fa fa-circle-o-notch"></i> 开启APP
                                    </button>
                                @endif

                                @if($system->wallet_status === 1)
                                    <button type="button" class="btn btn-danger wallet-btn-close"><i
                                                class="fa fa-circle-o-notch"></i> 关闭钱包
                                    </button>
                                @else
                                    <button type="button" class="btn btn-danger wallet-btn-open"><i
                                                class="fa fa-circle-o-notch"></i> 开启钱包
                                    </button>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
@endsection
@section('js')
    @parent
    <!-- jQuery file upload -->
    <script src="{{ asset('plugins/bower_components/icheck/icheck.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/icheck/icheck.init.js') }}"></script>
    <script src="{{ asset('js/jasny-bootstrap.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/dropify/dist/js/dropify.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/summernote/dist/summernote.min.js') }}"></script>
    <script>
        $(document).ready(function () {
            $('.dropify').dropify();
        });
    </script>
    <script src="{{ asset('js/cbpFWTabs.js') }}"></script>
    <script type="text/javascript">
        (function () {
            [].slice.call(document.querySelectorAll('.sttabs')).forEach(function (el) {
                new CBPFWTabs(el);
            });

        })();
    </script>
    <script>
        jQuery(document).ready(function () {

            $('.summernote').summernote({
                height: 350, // set editor height
                minHeight: null, // set minimum height of editor
                maxHeight: null, // set maximum height of editor
                focus: false, // set focus to editable area after initializing summernote$('.summernote').summernote({
                toolbar: [
                    // [groupName, [list of button]]
                    ['style', ['bold', 'italic', 'underline', 'clear']],
                    ['fontsize', ['fontsize']],
                    ['fontname', ['fontname']],
                    ['color', ['color']],
                    ['para', ['ul', 'ol', 'paragraph']],
                    ['height', ['height']],
                    ['insert', ['link', 'picture', 'video']],
                    ['view', ['fullscreen', 'codeview', 'help']]
                ],
                lang: 'zh-CN',
                placeholder: '内容',
                dialogsFade: true,
//                callbacks: {
//                    onImageUpload: function (files) {
//                        var data = new FormData();
//                        data.append("file", files[0]);
//                        $.ajax({
//                            data: data,
//                            type: "POST",
//                            headers: {
//                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
//                            },
//                            url: "/upload/img", /*填写后台上传文件的路径*/
//                            cache: false,
//                            contentType: false,
//                            processData: false,
//                            success: function (url) {/*url为上传成功后返回的图片路径*/
//                                var imgNode = document.createElement('img');
//                                imgNode.src = url;
//                                $('.summernote').summernote('insertNode', imgNode);
//                            }
//                        })
//                    }
//                }
            });

            $('.inline-editor').summernote({
                airMode: true
            });

        });
        //重置
        $('.btn-reset').click(function () {
            location.reload();
        });
        $(document).ready(function () {
            var hidden = $('#hidden').val();
            if (hidden === 'hidden') {
                toastsuccess($('#message').val());
            }
        });

        //关闭app
        $('.app-btn-close').click(function () {
            swal({
                    title: "",
                    text: "确定关闭么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/system/appStatus',
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });
        //开启app
        $('.app-btn-open').click(function () {
            swal({
                    title: "",
                    text: "确定开启么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/system/appStatus',
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });


        //关闭钱包
        $('.wallet-btn-close').click(function () {
            swal({
                    title: "",
                    text: "确定关闭么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/system/walletStatus',
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });
        //开启钱包
        $('.wallet-btn-open').click(function () {
            swal({
                    title: "",
                    text: "确定开启么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/system/walletStatus',
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

    </script>
@endsection